package com.dcd.controller;

import com.dcd.pojo.Video;
import com.dcd.service.VideoService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/VideoController")
@CrossOrigin
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 查询全部视频
     *
     * @return 返回所有视频
     */
    @RequestMapping("/select_all_video_program/{page_index}/{video_type_id}")
    public Map<String, Object> select_all_video_program(@PathVariable Integer page_index, @PathVariable Integer video_type_id) {
        return videoService.select_all_video_program(page_index, video_type_id);
    }

    /**
     * 查询所有视频排行榜
     *
     * @return 返回前十视频
     */
    @RequestMapping("/select_all_video_ranking")
    public List<Video> select_all_video_ranking() {
        return videoService.select_All_video_ranking();
    }

    /**
     * 根据车系id查询该车系所有视频
     *
     * @param car_series_id 车系id
     * @return
     */
    @RequestMapping("/select_series_id_video/{car_series_id}")
    public List<Video> select_series_id_video(@PathVariable Integer car_series_id) {
        return videoService.select_series_id_video(car_series_id);
    }

    /**
     * 查询指定节目下指定车系视频
     *
     * @param program_id    节目id
     * @param car_series_id 车系id
     * @param page_index    当前页数
     * @return
     */
    @RequestMapping("/select_appoint_program_all_video/{program_id}/{car_series_id}/{page_index}")
    public Map<String, Object> select_appoint_program_all_video(@PathVariable int program_id, @PathVariable int car_series_id, @PathVariable int page_index) {
        return videoService.select_appoint_program_all_video(program_id, car_series_id, page_index);
    }

    /**
     * 搜索查询视频
     *
     * @param solr_content 搜索文本内容
     * @param page_index   当前页数
     * @return
     */
    @RequestMapping("/select_video_by_solr/{solr_content}/{page_index}")
    public Map<String, Object> select_video_by_solr(@PathVariable String solr_content, @PathVariable int page_index) throws IOException, SolrServerException {
        return videoService.select_video_by_solr(solr_content, page_index);
    }

    /**
     * 根据视频id 查询视频
     * 返回 视频名称，路径 简介，以及用户资料
     * @param video_id   视频id
     * @return
     */
    @RequestMapping("/select_videoByID_video/{video_id}")
    public Video select_videoByID_video(@PathVariable Integer video_id){
        return videoService.select_videoByID_video(video_id);
    }

    /**
     * 根据视频id 查询该节目所有视频
     * 返回 视频基本信息 / 节目名称
     * @param video_id
     * @return
     */
    @RequestMapping("/select_video_id_all/{video_id}")
    public List<Video> select_video_id_all(@PathVariable Integer video_id){
        return videoService.select_video_id_all(video_id);
    }

}
